#! /usr/bin/env python
# _*_ coding: utf-8 _*_

''' application lifecycle and stdout and stderr '''

import wx
import sys

class Frame(wx.Frame):

    def __init__(self, parent, id, title):
        print "Frame __init__"
        wx.Frame.__init__(self, parent, id, title)

class App(wx.App):

    def __init__(self, redirect=False, filename=None):
        print "App __init__"
        wx.App.__init__(self, redirect, filename)

    def OnInit(self):
        print "OnInit" # output to stdout
        self.frame = Frame(parent=None, id=-1, title='Startup') # create framework
        self.frame.Show()
        self.SetTopWindow(self.frame)
        print>>sys.stderr, "A pretend error message" # output to stderr
        return True

    def OnExit(self):
        print "OnExit"

if __name__ == "__main__":
    app = App(False)
    print "before MainLoop"
    app.MainLoop()
    print "after MainLoop"

